﻿using System;

namespace Jiubang.Authentications {
    /// <summary>
    /// 用户会话信息。<br/>
    /// 开发人员可继承本类添加额外的用户信息。
    /// </summary>
    public class UserSession {
        private const string Key = "_UserSession";

        static UserSession() {
            Guest = new UserSession {UserID = -1, UserName = "游客", DepartmentCode = 0, RoleCode = 0};
        }

        private UserSession() {}

        /// <param name="userID">用户ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="departmentCode">部门代码</param>
        /// <param name="roleCode">角色代码</param>
        public UserSession(int userID, string userName, byte departmentCode, byte roleCode) {
            if (userID < 0) throw new ArgumentOutOfRangeException("userID");
            if (userName == null) throw new ArgumentNullException("userName");
            if (departmentCode == 0) throw new ArgumentOutOfRangeException("departmentCode");
            if (roleCode == 0) throw new ArgumentOutOfRangeException("roleCode");

            UserID = userID;
            UserName = userName;
            DepartmentCode = departmentCode;
            RoleCode = roleCode;
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserID { get; protected set; }

        /// <summary>
        /// 用户名称
        /// </summary>
        public string UserName { get; protected set; }

        /// <summary>
        /// 部门代码
        /// </summary>
        public byte DepartmentCode { get; protected set; }

        /// <summary>
        /// 角色代码
        /// </summary>
        public byte RoleCode { get; protected set; }

        /// <summary>
        /// 默认用户（游客）<br/>
        /// 用户ID为-1，部门及角色代码为0。名称为游客。
        /// </summary>
        public static UserSession Guest { get; private set; }
    }
}